package com.happy.entity;
// default package

import static javax.persistence.GenerationType.IDENTITY;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * Roles entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "roles", catalog = "sec", uniqueConstraints = {})
public class Roles implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 6289740667863046355L;
	private Integer id;
	private String roleName;
    private Set<Authority> authority=new LinkedHashSet<Authority>();
	// Constructors

	/** default constructor */
	public Roles() {
	}

	/** full constructor */
	public Roles(Integer id, String roleName) {
		this.id = id;
		this.roleName = roleName;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "roleName", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name = "authority_roles", joinColumns = { @JoinColumn(name = "rolesid") }, inverseJoinColumns = { @JoinColumn(name = "authorityID") })
	@Fetch(FetchMode.SUBSELECT)
	public Set<Authority> getAuthority() {
		return authority;
	}

	public void setAuthority(Set<Authority> authority) {
		this.authority = authority;
	}

}